﻿@using KRM.Core.Library
@model IEnumerable<KRM.Core.tblTicket>

@{
    ViewBag.Title = "ListTicket";
    Layout = "~/Views/Shared/_HRLayout.cshtml";
    var db = new KRM.Core.KRMEntities();    
}
@section Scripts{
    <script src="/js/mail.js"></script>
    <script src="/hr/js/plugins/ckeditor/ckeditor.js"></script>
}

<div id="EditTicket" class="modal fade" tabindex="-1" data-width="800">
    <div style="height: 500px">
        <div style="height: 220px"></div>
        <div class="ajax-loading"></div>
    </div>
</div>
<div id="CreateTicket" class="modal fade" tabindex="-1" data-width="800">
    <div style="height: 500px">
        <div style="height: 220px"></div>
        <div class="ajax-loading"></div>
    </div>
</div>
<div class="portlet alert">
    <div class="portlet-title">
        <div class="caption"><i class="icon-tags" style="font-size: 16px"></i>List Tickets</div>
    </div>
    <div class="">@Html.Partial("Partial/_MessageResult")</div>
    <form class="form-horizontal row" id="frFilterTicket" action="/EmailTicket/ListTicket" method="GET" style="margin-bottom: 5px">
        <label class="control-label col-md-1">Status:</label>
        <div class="col-md-3">@Html.DropDownList("FilterStatusID", null, new { @onchange = "FilterTicket()", @class = "form-control" })</div>
        <a onclick="CreateTicket(0)" href="#CreateTicket" class="btn btn-sm blue" data-toggle="modal" style="float: right; margin-right: 15px">Create ticket &nbsp;<i class="icon-plus"></i></a>
    </form>
    <table class="table table-bordered table-fix tbl-selected table-striped table-hover dataTable" style="background-color: #F8F8F8">
        <thead>
            <tr>
                <th>Subject</th>
                <th>Date Added</th>
                <th>User Added</th>
                <th>AssignedToUser</th>
                <th>DateStarted</th>
                <th>Status</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr onclick="ticketdetail('@item.TicketID')" style="cursor: pointer;">
                    <td>@item.Subject</td>
                    <td>@item.DateAdded</td>
                    <td>@db.tblUsers.Find(@item.AddedByUserID).Username</td>
                    <td>
                        @if (@item.AssignedToUserID != null && @item.AssignedToUserID != 0)
                        {
                            @db.tblUsers.Find(@item.AssignedToUserID).Username
                        }
                    </td>
                    <td>@item.DateStarted</td>
                    <td>@db.tblTicketStatus.Find(@item.StatusID).Status</td>
                    <td><a onclick="EditTicket(@item.TicketID) " class="btn btn-sm blue" data-toggle="modal" href="#EditTicket"><i class="icon-file-alt"></i> Edit</a></td>
                    <td><a onclick="javascript:return confirm('Are you sure to close this ticket ?');" class="btn btn-sm red" href="/EmailTicket/DeleteTicket/?ticketID=@item.TicketID&UserID=@Users.Current(User.Identity.Name).UserID"><i class="icon-archive"></i> Close</a></td>
                </tr>
            }
        </tbody>
    </table>

    <div class="row-fluid fr-ticketdetail" id="fr-ticketdetail"></div>
</div>
